﻿using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Web;

namespace AF_Web
{
    public static class ConfigGetter
    {
        public static string GetString(this NameValueCollection appSettings, string key)
        {
            string result = "";
            if (appSettings[key] != null)
            {
                result = appSettings[key];
            }
            return result;
        }

        public static int GetInt(this NameValueCollection appSettings, string key)
        {
            int result = -1;
            if (appSettings[key] != null)
            {
                string str = appSettings[key];
                int.TryParse(str, out result);
            }
            return result;
        }

        public static float GetFloat(this NameValueCollection appSettings, string key)
        {
            float result = -1;
            if (appSettings[key] != null)
            {
                string str = appSettings[key];
                float.TryParse(str, out result);
            }
            return result;
        }

        public static Guid GetGuid(this NameValueCollection appSettings, string key)
        {
            Guid result = Guid.Empty;
            if (appSettings[key] != null)
            {
                string str = appSettings[key];
                Guid.TryParse(str, out result);
            }
            return result;
        }

        public static DateTime GetDateTime(this NameValueCollection appSettings, string key)
        {
            DateTime result = DateTime.MinValue;
            if (appSettings[key] != null)
            {
                string str = appSettings[key];
                DateTime.TryParse(str, out result);
            }
            return result;
        }

    }
}